<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%--
  Created by IntelliJ IDEA.
  User: Persistent
  Date: 2022/11/20
  Time: 16:32
  To change this template use File | Settings | File Templates.
--%>
<html>
<head>
    <title>用户管理</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/bootstrap.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/AdminLTE.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/pagination.css">
    <script src="${pageContext.request.contextPath}/js/jquery.min.js"></script>
    <script src="${pageContext.request.contextPath}/js/bootstrap.js"></script>
    <script src="${pageContext.request.contextPath}/js/pagination.js"></script>
    <script src="${pageContext.request.contextPath}/js/user.js"></script>
    <script src="${pageContext.request.contextPath}/js/my.js"></script>

</head>
<body class="hold-transition skin-red sidebar-mini">
<!-- .box-body -->
<div class="box-header with-border">
    <h3 class="box-title">用户管理</h3>
</div>
<c:if test="${USER_SESSION.role == 'USER'}">
    <h3 style="text-align: center">无权限访问！</h3>
</c:if>
<c:if test="${USER_SESSION.role =='ADMIN'}">
<div class="box-body">
    <%--新增按钮：如果当前登录用户是管理员，页面展示新增按钮--%>

        <div class="pull-left">
            <div class="form-group form-inline">
                <div class="btn-group">
                    <button type="button" class="btn btn-default" title="新增用户" data-toggle="modal"
                            data-target="#addOrEditModal" onclick="resetFrom2()"> 新增
                    </button>
                </div>
            </div>
        </div>

    <!--工具栏 数据搜索 -->
    <div class="box-tools pull-right">
        <div class="has-feedback">
            <form action="" method="post"> <!--自动执行UserMapper的findAll方法-->
                用户名：<input name="name" value="${search.name}">&nbsp&nbsp&nbsp&nbsp
                邮箱：<input name="email" value="${search.email}">&nbsp&nbsp&nbsp&nbsp
                角色：<input name="role" value="${search.role}">&nbsp&nbsp&nbsp&nbsp
                <input class="btn btn-default" type="submit" value="查询">
            </form>
        </div>
    </div>
    <!--工具栏 数据搜索 /-->
    <!--数据列表-->
    <div class="table-box">
        <!-- 数据表格 -->
        <table id="dataList" class="table table-bordered table-striped table-hover dataTable text-center">
            <thead>
            <tr>
                <th class="sorting_asc">用户名</th>
                <th class="sorting">邮箱</th>
                <th class="sorting">角色</th>
                <th class="sorting">状态</th>
                <th class="text-center">操作</th>
            </tr>
            </thead>
            <tbody>
            <c:forEach items="${pageResult.rows}" var="user">
                <tr>
                    <td>${user.name}</td>
                    <td>${user.email}</td>
                    <td>${user.role}</td>
                    <td>${user.status}</td>
                    <td class="text-center">
                        <c:if test="${USER_SESSION.role =='ADMIN'}">
                            <button type="button" class="btn bg-olive btn-xs" data-toggle="modal"
                                    data-target="#addDeleteModal" onclick="findUserById(${user.id},'delete')"> 删除
                            </button>

                            <button type="button" class="btn bg-olive btn-xs" data-toggle="modal"
                                    data-target="#addOrEditModal" onclick="findUserById(${user.id},'edit')"> 编辑
                            </button>

                        </c:if>
                    </td>
                </tr>
            </c:forEach>
            </tbody>
        </table>
        <!-- 数据表格 /-->
        <%--分页插件--%>
        <div id="pagination" class="pagination"></div>
    </div>
    <!-- 数据表格 /-->
</div>
<!-- /.box-body -->

<!-- 添加和编辑图书的模态窗口 -->
<div class="modal fade" id="addOrEditModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
     aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h3 id="myModalLabel">用户信息</h3>
            </div>
            <div class="modal-body">
                <form id="addOrEditUser">
                    <span><input type="hidden" id="ebid" name="id"></span>
                    <table id="addOrEditTab" class="table table-bordered table-striped" width="800px">
                        <%--图书的id,不展示在页面--%>
                        <tr>
                            <td>用户名</td>
                            <td><input class="form-control" placeholder="用户名" name="name" id="ebname"></td>
                            <td>状态</td>
                            <td>
                                <select name="status" class="form-control" id="ebstatus">
                                    <option value="0" selected>0</option>
                                    <option value="1">1</option>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td>密码</td>
                            <td><input type='password' class="form-control" placeholder="密码" name="password" id="ebpassword"></td>
                            <td>确认密码</td>
                            <td><input type='password' class="form-control" placeholder="确认密码" name="password2" id="ebpassword2"></td>
                        </tr>
                        <tr>
                            <td>邮箱</td>
                            <td><input class="form-control" placeholder="邮箱" name="email" id="ebemail"></td>
                            <td>角色<br/></td>
                            <td>
                                <select name="role" class="form-control" id="ebrole">
                                    <option value="ADMIN">ADMIN</option>
                                    <option value="USER" selected>USER</option>
                                </select>
                            </td>
                        </tr>
                    </table>
                </form>
            </div>
            <div class="modal-footer">
                <button class="btn btn-success" data-dismiss="modal" aria-hidden="true" id="aoe" disabled onclick="addUserEdit()">保存
                </button>
                <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</button>
            </div>
        </div>
    </div>
</div>
<!--删除用户信息确认-->
<div class="modal fade" id="addDeleteModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel2"
     aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h3 id="myModalLabel2">确认删除信息</h3>
            </div>
            <div class="modal-body">
                <form id="addDeleteUser">
                    <table id="addDeleteTab" class="table table-bordered table-striped" width="800px">
                        <%--图书的id,不展示在页面--%>
                        <tr>
                            <td>用户名</td>
                            <td><input class="form-control" placeholder="用户名" name="name" id="dename"></td>
                            <td>ID</td>
                            <td>
                                <input class="form-control" placeholder="id" name="id" id="deid">
                            </td>
                        </tr>
                        <tr>
                            <td>邮箱</td>
                            <td><input class="form-control" placeholder="邮箱" name="email" id="deemail"></td>
                            <td>角色<br/></td>
                            <td><input class="form-control" placeholder="角色" name="role" id="derole"></td>
                        </tr>
                    </table>
                </form>
            </div>
            <div class="modal-footer">
                <button class="btn btn-success" data-dismiss="modal" aria-hidden="true" onclick="deleteUser()">确认删除
                </button>
                <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</button>
            </div>
        </div>
    </div>
</div>
</c:if>
</body>
<script>
    /*分页插件展示的总页数*/
    pageargs.total = Math.ceil(${pageResult.total}/pageargs.pagesize);
    /*分页插件当前的页码*/
    pageargs.cur = ${pageNum}
        /*分页插件页码变化时将跳转到的服务器端的路径*/
        pageargs.gourl = "${gourl}"
    /*保存搜索框中的搜索条件，页码变化时携带之前的搜索条件*/
    bookVO.name = "${search.name}"
    bookVO.author = "${search.email}"
    bookVO.press = "${search.role}"
    /*分页效果*/
    pagination(pageargs);
</script>
</html>
